package com.zzz.common;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // 输入三个矩形
        int lineCount = 3;
        int num = 4;

        int[][] coordinates = new int[lineCount][num];

        Scanner scanner = new Scanner(System.in);

        for (int i = 0; i < lineCount; i++) {
            for (int j = 0; j < num; j++) {
                coordinates[i][j] = scanner.nextInt();
            }
        }

//        System.out.println("输入的坐标是：" + Arrays.toString(coordinates[0]));
//        System.out.println("输入的坐标是：" + Arrays.toString(coordinates[1]));
//        System.out.println("输入的坐标是：" + Arrays.toString(coordinates[2]));

        // 通过 calculateCommon 计算两矩形之间的公共的矩形
        int[] common1 = calculateCommon(coordinates[0], coordinates[1]);
//        System.out.println("第一个公共：" + Arrays.toString(common1));

        int[] common2 = calculateCommon(common1, coordinates[2]);
//        System.out.println("第二个公共：" + Arrays.toString(common2));

        // women
        int area = common2[2] * common2[3];

        System.out.println(area);
    }

    /*
       输入两矩形的坐标，输出公共矩形，如果不存在公共就输出全0
     */
    public static int[] calculateCommon(int[] coordinates1, int[] coordinates2) {

        // 以坐标1表示的矩形为范围，将坐标2表示的矩形四个点来判断是否在范围内，如果在的话表示相交
        int x1min = coordinates1[0], x1max = x1min + coordinates1[2];
        int y1max = coordinates1[1], y1min = y1max - coordinates1[3];

        // 矩形2的横坐标，纵坐标的范围是
        int x2min = coordinates2[0], x2max = x2min + coordinates2[2];
        int y2max = coordinates2[1], y2min = y2max - coordinates2[3];

        int commonXMin = 0, commonXMax = 0, commonYMin = 0, commonYMax = 0;

        // 四种情况下都不会产生交集
        if (x2min >= x1max || x2max <= x1min || y1min >= y2max || y1max <= y2min) {
            return new int[]{0, 0, 0, 0};
        }

        // 产生x轴交集的情况

        // 产生 y 轴交集的情况
        if (x2max >= x1max && x2min <= x1min) {
            commonXMin = x1min;
            commonXMax = x1max;
        }

        if (x2max <= x1max && x2min >= x1min) {
            commonXMin = x2min;
            commonXMax = x2max;
        }

        if (x2max >= x1max && x2min >= x1min) {
            commonXMin = x2min;
            commonXMax = x1max;
        }

        if (x2max <= x1max && x2min <= x1min) {
            commonXMin = x1min;
            commonXMax = x2max;
        }

        // 第一种情况
        if (y2max >= y1max && y2min <= y1min) {
            commonYMin = y1min;
            commonYMax = y1max;
        }
        // 第二种情况
        if (y2max <= y1max && y2min >= y1min) {
            commonYMin = y2min;
            commonYMax = y2max;
        }
        // 第三种情况
        if (y2max >= y1max && y2min >= y1min) {
            commonYMin = y2min;
            commonYMax = y1max;
        }
        if (y2max <= y1max && y2min <= y1min) {
            commonYMin = y1min;
            commonYMax = y2max;
        }

        int commonX = commonXMin;
        int commonY = commonYMax;
        int commonWidth = commonXMax - commonXMin;
        int commonHigh = commonYMax - commonYMin;

        return new int[]{commonX, commonY, commonWidth, commonHigh};
    }
}
